﻿using System;
using System.Collections.Generic;
using UnityEngine.EventSystems;

namespace Core.Audio
{
    public static class AudioEvent
    {
        public static readonly Dictionary<EGameEvent, Type> Dict = new()
        {
            { EGameEvent.Enable, typeof(UIAudioEvent) },
            { EGameEvent.Disable, typeof(UIAudioEvent) },
            { EGameEvent.PointerClick, typeof(UIAudioPointerClick) },
            { EGameEvent.PointerDown, typeof(UIAudioPointerDown) },
            { EGameEvent.PointerUp, typeof(UIAudioPointerUp) },
            { EGameEvent.PointerEnter, typeof(UIAudioPointerEnter) },
            { EGameEvent.PointerExit, typeof(UIAudioPointerExit) },
        };
    }

    public class UIAudioEvent : UIBehaviour
    {
        protected UIAudioPlayer Player;

        protected override void Awake()
        {
            Player = transform.GetComponent<UIAudioPlayer>();
        }

        protected override void OnEnable()
        {
            Player.HandleGameEvent(EGameEvent.Enable);
        }

        protected override void OnDisable()
        {
            Player.HandleGameEvent(EGameEvent.Disable);
        }
    }

    public class UIAudioPointerClick : UIAudioEvent, IPointerClickHandler
    {
        public void OnPointerClick(PointerEventData _)
        {
            Player.HandleGameEvent(EGameEvent.PointerClick);
        }
    }

    public class UIAudioPointerDown : UIAudioEvent, IPointerDownHandler
    {
        public void OnPointerDown(PointerEventData _)
        {
            Player.HandleGameEvent(EGameEvent.PointerDown);
        }
    }

    public class UIAudioPointerUp : UIAudioEvent, IPointerUpHandler
    {
        public void OnPointerUp(PointerEventData _)
        {
            Player.HandleGameEvent(EGameEvent.PointerUp);
        }
    }

    public class UIAudioPointerEnter : UIAudioEvent, IPointerEnterHandler
    {
        public void OnPointerEnter(PointerEventData _)
        {
            Player.HandleGameEvent(EGameEvent.PointerEnter);
        }
    }

    public class UIAudioPointerExit : UIAudioEvent, IPointerExitHandler
    {
        public void OnPointerExit(PointerEventData _)
        {
            Player.HandleGameEvent(EGameEvent.PointerExit);
        }
    }

    //public class UIAudioSubmit : UIAudioEvent, ISubmitHandler
    //{
    //    public void OnSubmit(BaseEventData eventData)
    //    {
    //        emitter.HandleGameEvent(EGameEvent.Submit);
    //    }
    //}

    //public class UIAudioMove : UIAudioEvent, IMoveHandler
    //{
    //    public void OnMove(AxisEventData eventData)
    //    {
    //        emitter.HandleGameEvent(EGameEvent.Move);
    //    }
    //}

    //public class UIAudioSelect : UIAudioEvent, ISelectHandler
    //{
    //    public void OnSelect(BaseEventData _)
    //    {
    //        emitter.HandleGameEvent(EGameEvent.Select);
    //    }
    //}

    //public class UIAudioDeselect : UIAudioEvent, IDeselectHandler
    //{
    //    public void OnDeselect(BaseEventData _)
    //    {
    //        emitter.HandleGameEvent(EGameEvent.Deselect);
    //    }
    //}
}
